using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.UserContrl
{
	public class PhoneContactListItem : UserControl
	{
		private const string TAG = "PhoneContactListItem";
		public static bool sBIsListScrolling;
		private int mNID;
		public static DependencyProperty ListItemProperty;
		private static int sNInstanceID;
		private static Dictionary<int, PhoneContactListItem> sDictItemIsShown;
		private static Dictionary<string, MobileContact> sDictFetchingCons;
		internal Button btnLayoutRoot;
		internal Grid LayoutRoot;
		internal TextBlock txtNickName;
		internal StackPanel panelIsMMUser;
		internal TextBlock txtTips;
		internal Image addIcon;
		internal TextBlock txtPhoneNum;
		private bool _contentLoaded;
		public event ListItemClick ItemClick;
		public MobileContact ItemObject
		{
			get
			{
				return (MobileContact)base.GetValue(PhoneContactListItem.ListItemProperty);
			}
			set
			{
				base.SetValue(PhoneContactListItem.ListItemProperty, value);
			}
		}
		public PhoneContactListItem()
		{
			this.mNID = PhoneContactListItem.sNInstanceID++;
			this.InitializeComponent();
			base.SetValue(TiltEffect.IsTiltEnabledProperty, true);
			base.add_Loaded(new RoutedEventHandler(this.PhoneContactListItem_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.PhoneContactListItem_Unloaded));
		}
		static PhoneContactListItem()
		{
			PhoneContactListItem.sBIsListScrolling = false;
			PhoneContactListItem.ListItemProperty = DependencyProperty.Register("ItemObject", typeof(MobileContact), typeof(PhoneContactListItem), new PropertyMetadata(null, new PropertyChangedCallback(PhoneContactListItem.OnItemPropertyChanged)));
			PhoneContactListItem.sNInstanceID = 0;
			PhoneContactListItem.sDictItemIsShown = new Dictionary<int, PhoneContactListItem>();
			PhoneContactListItem.sDictFetchingCons = new Dictionary<string, MobileContact>();
		}
		private void PhoneContactListItem_Unloaded(object sender, RoutedEventArgs e)
		{
			if (PhoneContactListItem.sDictItemIsShown.ContainsKey(this.mNID))
			{
				PhoneContactListItem.sDictItemIsShown.Remove(this.mNID);
			}
		}
		private void PhoneContactListItem_Loaded(object sender, RoutedEventArgs e)
		{
			if (!PhoneContactListItem.sDictItemIsShown.ContainsKey(this.mNID))
			{
				PhoneContactListItem.sDictItemIsShown.Add(this.mNID, this);
			}
		}
		private void btnLayoutRoot_Click(object sender, RoutedEventArgs e)
		{
			if (this.ItemClick != null)
			{
				this.ItemClick(this, this.ItemObject);
			}
		}
		private static void OnItemPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == PhoneContactListItem.ListItemProperty)
			{
				(dependencyObject_0 as PhoneContactListItem).OnListItemPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void OnListItemPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			this.RefreshItem(dependencyPropertyChangedEventArgs_0.get_NewValue() as MobileContact);
		}
		private void RefreshItem(MobileContact item)
		{
			if (item == null)
			{
				return;
			}
			this.txtPhoneNum.set_Text(item.strMobile);
			this.txtNickName.set_Text(item.strRealName);
			if (item.nStatus == 1)
			{
				this.txtTips.set_Text(strings.QQFriend_Add);
				this.txtTips.set_Foreground(MMTheme.GetInstance().SNS_MSGPAGE_TIME_BRUSH);
				this.addIcon.set_Visibility(0);
				return;
			}
			if (item.nStatus == 0)
			{
				this.txtTips.set_Text(strings.Friend_Invite);
				this.txtTips.set_Foreground(MMTheme.GetInstance().COMMON_BRUSH);
				this.addIcon.set_Visibility(1);
				return;
			}
			this.txtTips.set_Text(strings.QQFriend_Added);
			this.txtTips.set_Foreground(MMTheme.GetInstance().SNS_MSGPAGE_TIME_BRUSH);
			this.addIcon.set_Visibility(1);
		}
		public static void RefreshStatusInView(string strUserName)
		{
			if (PhoneContactListItem.sDictItemIsShown != null)
			{
				IEnumerable<PhoneContactListItem> values = PhoneContactListItem.sDictItemIsShown.get_Values();
				using (IEnumerator<PhoneContactListItem> enumerator = values.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						PhoneContactListItem current = enumerator.get_Current();
						if (current.ItemObject != null && current.ItemObject.strUsrName != null && current.ItemObject.strUsrName == strUserName)
						{
							current.RefreshItem(current.ItemObject);
						}
					}
				}
			}
		}
		public static void RequestHeadImgInView()
		{
		}
		public static void RefreshHeadImgInView(Dictionary<string, Stream> dictImages)
		{
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/PhoneContact/PhoneContactListItem.xaml", 2));
			this.btnLayoutRoot = (Button)base.FindName("btnLayoutRoot");
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.txtNickName = (TextBlock)base.FindName("txtNickName");
			this.panelIsMMUser = (StackPanel)base.FindName("panelIsMMUser");
			this.txtTips = (TextBlock)base.FindName("txtTips");
			this.addIcon = (Image)base.FindName("addIcon");
			this.txtPhoneNum = (TextBlock)base.FindName("txtPhoneNum");
		}
	}
}
